<#assign base=request.contextPath />
<!DOCTYPE html>
<div class="row">
	<div class="col-md-12 col-sm-12 col-xs-12">
		<div class="x_panel">
			<div class="x_title">
				<#if userType=="1">
					<h2>农户管理 <small></small></h2>
				</#if>
				<#if userType=="2">
					<h2>代理商管理 <small></small></h2>
				</#if>
				<#if userType=="3">
					<h2>业务员管理 <small></small></h2>	
				</#if>
				<#if userType=="4">
					<h2>营业部管理 <small></small></h2>
				</#if>
				<#if userType=="5">
					<h2>代理商业务员管理 <small></small></h2>
				</#if>
		        <div class="clearfix"></div>
	        </div>
			<div class="x_content">
				<div class="row">
					<div class="col-sm-2">
						<button type="button" class="btn btn-primary" onclick="toAdd();"><i class="fa fa-plus"></i> 新增</button>
					</div>
					<div class="col-sm-10">
						<div class="pull-right">
							<#if userType=="1">
							<label><input type="text" id="userName" value="${userName!''}" class="form-control input-sm" placeholder="请输入农户用户名"></label>
							<label><input type="text" id="realName" value="${realName!''}" class="form-control input-sm" placeholder="请输入农户姓名"></label>
							</#if>
							<#if userType=="2">
							<label><input type="text" id="userNo" value="${userNo!''}" class="form-control input-sm" placeholder="请输入代理商编号"></label>
							<label><input type="text" id="realName" value="${realName!''}" class="form-control input-sm" placeholder="请输入代理商姓名"></label>
							</#if>
							<#if userType=="4">
							<label><input type="text" id="userName" value="${userName!''}" class="form-control input-sm" placeholder="请输入营业部名称"></label>
							<label><input type="text" id="realName" value="${realName!''}" class="form-control input-sm" placeholder="请输入营业部负责人姓名"></label>
							</#if>
							<#if userType=="3"||userType=="5">
							<label><input type="text" id="userNo" value="${userNo!''}" class="form-control input-sm" placeholder="请输入业务员编号"></label>
							<label><input type="text" id="realName" value="${realName!''}" class="form-control input-sm" placeholder="请输入业务员姓名"></label>
							</#if>
							<label><input type="text" id="phone" value="${phone!''}" class="form-control input-sm" placeholder="请输入手机号"></label>
							<label><input type="text" id="cardNo" value="${cardNo!''}" class="form-control input-sm" placeholder="请输入身份证号"></label>
							<label>
								<select id="areaProvince" name="areaProvince" class="form-control select2">
		                        	<option value="">所属省</option>
		                        	<#list listProvince as province>
		                        	<option value="${province.code}" <#if (areaProvince==province.code)>selected="selected"</#if>>${province.cityName}</option>
		                        	</#list>
	                    		</select>
	                    	</label>
	                    	<label>
								<select id="areaCity" name="areaCity" class="form-control select2">
		                        	<option value="">所属市</option>
		                        	<#list listCity as city>
		                        	<option value="${city.code}" <#if (areaCity==city.code)>selected="selected"</#if>>${city.cityName}</option>
		                        	</#list>
	                    		</select>
	                    	</label>
	                    	<label>
								<select id="areaDistrict" name="areaDistrict" class="form-control select2">
		                        	<option value="">所属区</option>
		                        	<#list listDistrict as district>
		                        	<option value="${district.code}" <#if (areaDistrict==district.code)>selected="selected"</#if>>${district.cityName}</option>
		                        	</#list>
	                    		</select>
	                    	</label>
							<button type="button" class="btn btn-dark" onclick="selectQuery('');"><i class="fa fa-search"></i> 查询</button>
						</div>
					</div>
				</div>
				<div class="table-responsive">
					<table class="table table-striped jambo_table bulk_action">
						<thead>
							<tr class="headings">
								<#if userType=="1">
								<th class="column-title">农户用户名 </th>
								<th class="column-title">农户姓名 </th>
								<th class="column-title">手机号 </th>
			                    <th class="column-title">身份证号 </th>
			                    <th class="column-title">审核状态 </th>
								</#if>
								<#if userType=="2">
								<th class="column-title">代理商编号 </th>
								<th class="column-title">代理商姓名 </th>
								<th class="column-title">手机号 </th>
			                    <th class="column-title">身份证号 </th>
								</#if>
			                    <#if userType=="4">
								<th class="column-title">营业部名称 </th>
								<th class="column-title">营业部负责人 </th>
								<th class="column-title">手机号 </th>
			                    <th class="column-title">身份证号 </th>
								</#if>
								<#if userType=="3"||userType=="5">
								<th class="column-title">业务员编号 </th>
								<th class="column-title">业务员姓名 </th>
								<th class="column-title">手机号 </th>
			                    <th class="column-title">身份证号 </th>
								</#if>
			                    <th class="column-title">所属省 </th>
			                    <th class="column-title">所属市</th>
			                    <th class="column-title">所属区县</th>
			                    <th class="column-title">更新时间 </th>
			                    <th class="column-title no-link last"><span class="nobr">操作</span></th>
			                </tr>
						</thead>
			            <tbody>
			            	<#list page.content as obj>
			            	<tr class="even pointer">
			            		<#if userType=="1">
			                    <td class=" ">${(obj.userName)!'' }</td>
			                    <td class=" ">${(obj.realName)!''} </td>
			                    <td class=" ">${(obj.phone)!''} </td>
			                    <td class=" ">${(obj.cardNo)!''} </td>
			                    <td class=" ">
			                    	<#if (obj.isChecked==1)>已通过</#if>
			                    	<#if (obj.isChecked==0)><span style="color:red;">未通过</span></#if>
			                    </td>
			                    </#if>
			            		<#if userType=="2">
			                    <td class=" ">${(obj.userNo)!'' }</td>
			                    <td class=" ">${(obj.realName)!''} </td>
			                    <td class=" ">${(obj.phone)!''} </td>
			                    <td class=" ">${(obj.cardNo)!''} </td>
			                    </#if>
			                    <#if userType=="4">
			                    <td class=" ">${(obj.userName)!'' }</td>
			                    <td class=" ">${(obj.realName)!''} </td>
			                    <td class=" ">${(obj.phone)!''} </td>
			                    <td class=" ">${(obj.cardNo)!''} </td>
			                    </#if>
			                    <#if userType=="3"||userType=="5">
			                    <td class=" ">${(obj.userNo)!'' }</td>
			                    <td class=" ">${(obj.realName)!''} </td>
			                    <td class=" ">${(obj.phone)!''} </td>
			                    <td class=" ">${(obj.cardNo)!''} </td>
			                    </#if>
			                    <td class=" ">${(obj.areaProvince.cityName)!''} </td>
			                    <td class=" ">${(obj.areaCity.cityName)!''} </td>
			                    <td class=" ">${(obj.areaDistrict.cityName)!''} </td>
			                    <td class=" ">${(obj.updateTime)!'' }</td>
			                    <td class="last">
			                    <!--  
			                    	<button type="button" class="btn btn-dark btn-xs" onclick="toEdit(${(obj.id)?c});"><i class="fa fa-search"></i> 查看</button>
			                    	-->
			                    	<#if userType=="1">
			                    		<button type="button" class="btn btn-warning btn-xs" onclick="toCheck(${(obj.id)?c});"><i class="fa fa-edit"></i> 审核</button>
			                    	</#if>
			                    	<button type="button" class="btn btn-warning btn-xs" onclick="toEdit(${(obj.id)?c});"><i class="fa fa-edit"></i> 编辑</button>
			                    </td>
			                </tr>
			                </#list>
			            </tbody>
					</table>
				</div>
			</div>
			<#include "../common/paginator.ftl" />
		</div>
	</div>
</div>
<script type="text/javascript">
//select2
$(".select2").select2({width: "100px"});

$("#areaProvince").change(function(){
	$.post("${base}/common/getAreaList", {"pCode":$(this).val()}, function(data) {
		if (data.flag) {
			$("#areaCity").empty();
			$("#areaCity").append("<option value=''>所属市</option>");
			$.each(data.obj, function(i, n){
				$("#areaCity").append("<option value='"+n.code+"'>"+n.cityName+"</option>");
			});
		}
	});
});
$("#areaCity").change(function(){
	$.post("${base}/common/getAreaList", {"pCode":$(this).val()}, function(data) {
		if (data.flag) {
			$("#areaDistrict").empty();
			$("#areaDistrict").append("<option value=''>所属区县</option>");
			$.each(data.obj, function(i, n){
				$("#areaDistrict").append("<option value='"+n.code+"'>"+n.cityName+"</option>");
			});
		}
	});
});

/*进入添加*/
function toAdd(){
	var data = {
		"userType":'${userType}',
	};
	$("#main_content").load('${base}/gx/user/toAdd',data);	
}

/*进入编辑*/
function toEdit(id){
	$("#main_content").load('${base}/gx/user/toEdit',{"id":id,"userType":'${userType}'});	
}

/*进入审核*/
function toCheck(id){
	$("#main_content").load('${base}/gx/user/toCheck',{"id":id,"userType":'${userType}'});	
}

function selectQuery(pageIndex){
	var data = {
		"pageIndex":pageIndex,
		//其余查询条件自行添加
		"userType":'${userType}',
		"userName":$.trim($("#userName").val()),
		"userNo":$.trim($("#userNo").val()),
		"realName":$.trim($("#realName").val()),
		"cardNo":$.trim($("#cardNo").val()),
		"phone":$.trim($("#phone").val()),
		"areaProvince":$.trim($("#areaProvince").val()),
		"areaCity":$.trim($("#areaCity").val()),
		"areaDistrict":$.trim($("#areaDistrict").val()),
	};
	$("#main_content").load('${base}/gx/user/list',data);	
}
</script>
